var userInfo = {
		avatar: "https://we-retail-static-1300977798.cos.ap-guangzhou.myqcloud.com/retail-ui/components-exp/avatar/avatar-1.jpg",
		userName: "Three",
		couponNum: 10,
		point: 6,
		payNum: 58,
		sendNum: 3,
		receiveNum: 5
	},

	orderTags = [{
			"id": 1,
			"name": "待付款",
			"num": 0
		},
		{
			"id": 2,
			"name": "待发货",
			"num": 0
		},
		{
			"id": 3,
			"name": "待收货",
			"num": 0
		},
		{
			"id": 4,
			"name": "待评价",
			"num": 0
		},
		{
			"id": 5,
			"name": "退款/售后",
			"num": 0
		}
	];

$(() => {
	queryUserInfo();
	initUserListener();
})

queryUserInfo = () => {
	$(`#avatar`).attr('src', userInfo.avatar);
	$(`#name`).html(userInfo.userName);
	$(`#num_coupon`).html(userInfo.couponNum);
	$(`#num_point`).html(userInfo.point);
	orderTags[0].num = userInfo.payNum;
	orderTags[1].num = userInfo.sendNum;
	orderTags[2].num = userInfo.receiveNum;

	handleOrderTag();
}

handleOrderTag = () => {
	$(`#order_tag`).html('');
	let itemHtml = ``;
	orderTags.forEach((e, i) => {
		let id = e.id;
		let num = e.num;
		let bagdeItem = ``;
		if (num > 0) {
			bagdeItem = `<span class="bagde">${num}</span>`;
		}
		itemHtml += `<div class="order_tag" onclick="jumpOrder(${e.id})">
							${bagdeItem}
							<img src="img/ic_evaluate.png" class="icon" />
							${e.name}
					</div>`
	})
	$(`#order_tag`).html(itemHtml);
}

initUserListener = () => {
	$("#user_info").on('click', (e) => {
		navigateTo(`page/user/personer.html`)
	});
	$("#all_order").on('click', (e) => {
		jumpOrder(0);
	});
	$("#menu_address").on('click', (e) => {
		navigateTo(`page/common/address.html`)
	});
	$("#menu_coupon").on('click', (e) => {
		navigateTo(`page/coupon/index.html`)
	});
	$("#menu_point").on('click', (e) => {
		navigateTo(`page/user/point.html`)
	});
	$("#menu_help").on('click', (e) => {
		navigateTo(`page/exam/mock_list.html`)
	});
	$("#menu_service").on('click', (e) => {
		onCallphone('13924154998')
	});
	$("#menu_questionnaire").on('click', (e) => {
		navigateTo(`page/common/questionnaire.html`)
	});
}

jumpOrder = (index) => {
	if (index == 5) {
		navigateTo(`page/order/after_service_list.html`)
	} else{
		navigateTo(`page/order/index.html?index=${index}`)
	}
}
